﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Moon.Sql
{
    public class MySqlDeleteable<T> : DeleteableProvide<T>
    {
        public MySqlDeleteable(IDatabase _Database)
            : base(_Database) { }

        public override SqlBuilderResult ToSql()
        {
            SqlBuilderResult sqlResult = GetSqlParam();
            string sql = "delete {2} from {0} {2} where {1}";
            if (_Limit.HasValue)
            {
                sql = "delete from {0} where {1} limit " + _Limit;
            }
            return new SqlBuilderResult()
            {
                Sql = string.Format(sql,
                    IsQuote ? Database.SqlDialect.SetSqlName(MasterTableName) : MasterTableName,
                    sqlResult.Sql,
                    CommonUtils.TableAliasName),
                DynamicParameters = sqlResult.DynamicParameters
            };
        }
    }
}
